/**
 *====================================================
 * 文件名称: FinanceEvidentiaryCategoryServiceImpl.java
 * 修订记录：
 * No    日期				作者(操作:具体内容)
 * 1.    2015年09月23日	chenxy(创建:创建文件)
 *====================================================
 * 类描述：(说明未实现或其它不应生成javadoc的内容)
 */
package com.yuexunit.finance.project.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.bulkstock.entity.lexicon.MaterialTemplateEnum;
import com.yuexunit.finance.project.entity.FinanceEvidentiaryCategoryEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.persist.PersistUtil;

/**
 * @ClassName: FinanceEvidentiaryCategoryServiceImpl
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author chenxy
 * @date 2015年09月23日 18:56:17
 */
@Implements(FinanceEvidentiaryCategoryService.class)
public class FinanceEvidentiaryCategoryServiceImpl implements FinanceEvidentiaryCategoryService {

	@Override
	public Long createEvidentiaryCategory(FinanceEvidentiaryCategoryEntity entity) {
		if (entity.getCheckedRequired() == null) {
			entity.setCheckedRequired(MaterialTemplateEnum.UNKNOWN);
		}
		PersistUtil.insert(entity);
		return entity.getEvidentiaryCategoryId();
	}

	@Override
	public List<FinanceEvidentiaryCategoryEntity> inquireFinanceEvidentiaryCategoryList(Long financeId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceEvidentiaryCategoryEntity.class);
		criteria.add(Restrictions.eq("financeId", financeId));
		List<FinanceEvidentiaryCategoryEntity> financeEvidentiaryCategoryList = PersistUtil.get(criteria);
		return financeEvidentiaryCategoryList;
	}

	@Override
	public FinanceEvidentiaryCategoryEntity inquireFinanceEvidentiaryCategory(Long financeId, Long templateId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceEvidentiaryCategoryEntity.class);
		criteria.add(Restrictions.eq("financeId", financeId));
		criteria.add(Restrictions.eq("templateId", templateId));
		List<FinanceEvidentiaryCategoryEntity> list = PersistUtil.get(criteria);
		if (list.isEmpty()) {
			return null;
		}
		return list.get(0);
	}

}
